package com.edu.exam.enums;

/**
 * 会话配置状态枚举
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-12
 */
public enum SessionConfigStatus {
    DRAFT("DRAFT", "草稿"),
    ACTIVE("ACTIVE", "激活"),
    SUSPENDED("SUSPENDED", "暂停"),
    DEPRECATED("DEPRECATED", "废弃");

    private final String code;
    private final String description;

    SessionConfigStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码查找枚举值
     *
     * @param code 枚举代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码不存在
     */
    public static SessionConfigStatus fromCode(String code) {
        for (SessionConfigStatus status : SessionConfigStatus.values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown session config status code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 枚举描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述不存在
     */
    public static SessionConfigStatus fromDescription(String description) {
        for (SessionConfigStatus status : SessionConfigStatus.values()) {
            if (status.description.equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown session config status description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}